﻿#if UNITY_ANDROID

namespace Blaze.Utilities.AppImplements
{
    using UnityEngine;

    /// <summary>
    /// <see cref="IAppUtility"/>的Android实现。
    /// </summary>
    public class AndroidImplement : IAppUtility
    {
        #region IAppUtility Members

        /// <summary>
        /// 获取剪贴板的文本内容。
        /// </summary>
        public string GetClipboardText()
        {
            return mAppUtility.CallStatic<string>("getClipboardText");
        }

        /// <summary>
        /// 安装指定的安装包。
        /// </summary>
        /// <param name="filePath">游戏包文件路径</param>
        public void Install(string filePath)
        {
            mAppUtility.CallStatic("install", filePath);
        }

        /// <summary>
        /// 获取一个值，表示指定的应用是否已经安装。
        /// </summary>
        /// <param name="bundleId">包名</param>
        public bool IsInstalled(string bundleId)
        {
            return mAppUtility.CallStatic<bool>("isAppInstalled", bundleId);
        }

        /// <summary>
        /// 打开外部链接地址。
        /// </summary>
        /// <param name="url">地址</param>
        public void OpenUrl(string url)
        {
            mAppUtility.CallStatic("openUrl", url);
        }

        /// <summary>
        /// 设置剪贴板的文本内容。
        /// </summary>
        public void SetClipboardText(string text)
        {
            mAppUtility.CallStatic("setClipboardText", text);
        }

        /// <summary>
        /// 启动指定包名的应用。
        /// </summary>
        /// <param name="bundleId">包名</param>
        public void Start(string bundleId)
        {
            mAppUtility.CallStatic("startActivity", bundleId);
        }

        #endregion

        private readonly AndroidJavaClass mAppUtility = new AndroidJavaClass("com.blaze.unityplugin.AppUtility");
    }
}

#endif